<%@page import="java.util.HashMap,utils.msg.PollingQueryRunnable"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>


<style>
.data_list .diary_datas {
	padding: 5px;
}
</style>

<div class="infoList" align="center">
	<c:if test="${! empty infoList}">
		<div></div>
		<table class="table table-bordered table-hover">
			<tr>
				<th>用户事件id</th>
				<th>事件描述</th>
				<th>用户名</th>
				<th>手机</th>
				<th>邮箱</th>
				<th>数据库</th>
				<th>表</th>
				<th>事件类型</th>
				<th>事件条件类型</th>
				<th>轮询时间</th>
				<th>时间片</th>
				<th>操作</th>
			</tr>
			<c:forEach var="info" items="${infoList }">
				<tr>
					<td><span>&nbsp;${info.ueId}</span></td>
					<td><span>&nbsp;${info.desc}</span></td>
					<td><span>&nbsp;${info.username }</span></td>
					<td><span>&nbsp;${info.phoneNumber }</span></td>
					<td><span>&nbsp;${info.email }</span></td>
					<td><span>&nbsp;${info.dbName }</span></td>
					<td><span>&nbsp;${info.tableName }</span></td>
					
					<td><span>&nbsp;${info.eventType }</span></td>
					<td><span>&nbsp;${info.type }</span></td>
					<td><span>&nbsp;${info.pollingTime }</span></td>
					<td><span>&nbsp;${info.timeSpan }</span></td>

					<td><button type="button" class="btn btn-primary" id="abc"
						data-toggle="modal" data-target="#myModal" data-id="${info.ueId}">
							查看
						</button> 
						&nbsp;&nbsp; <button type="button" class="btn btn-primary"
						onclick="javascript:window.location='AdminServlet?method=delUe&ueId=${info.ueId}'">
							删除
						</button>
					</td>

				</tr>
			</c:forEach>
		</table>
	</c:if>

	
</div>

<!-- 模态框（Modal） -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">&times;</button>
				<h4 class="modal-title" id="myModalLabel">事件详细信息查看</h4>
			</div>
			<div class="modal-body">
				<div id="efcListBody"></div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<button type="button" class="btn btn-primary" data-toggle="modal" data-id="2" id="add"
					data-target="#myModal1">增加</button>
				<button type="button" class="btn btn-primary" data-id="2" id="del">删除</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
</div>
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">添加</h4>
				</div>
				<div class="modal-body">
					<form role="form" id="addEventFieldsCondition">
						<div class="form-group">
							<label class="col-sm-2 control-label">字段名</label>
		              		<select class="form-control" id="fields" name="fields">
		              					<option value="0">请选择...</option>
		              		</select>
		          			</div>
		              	<div class="form-group">
			                <label class="col-sm-2 control-label">条件</label>
			                <select class="form-control" id="condition" name="condition">
			               		<option value="0">请选择...</option>
			               		<option value=">">大于</option>
			               		<option value="<">小于</option>
			               		<option value="=">等于</option>
			                </select>
			            </div>
			            <div class="form-group">
			               <label class="col-sm-2 control-label">数值</label>
			               <input class="form-control" id="value" name="value" type="text" type="text" placeholder=""/>
			            </div>
			            <input id="ueId" name="ueId" type="hidden" value="123">
		            </form>
	            </div><!-- /.modal-body -->
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
				<button type="button" class="btn btn-primary" id="submit">提交</button>
			</div>
		</div>
		<!-- /.modal-content -->
	</div>
	<!-- /.modal -->
	
<script>
    var id;
	$('#myModal').on('show.bs.modal',function(event){
		var button = $(event.relatedTarget);
		var ueId = button.data('id');
		id = ueId;
		$("#add").attr("data-id",ueId);
		//使用jQuery的load方法将指定ueId的所有EventFieldCondtion的值放入efcListBody这个<div>
		$("#efcListBody").load("EventFieldsConditionServlet?method=getFieldListByUeid&ueId="+ueId);
	})
	
	$('#myModal1').on('show.bs.modal',function(event){
		var ueId = $("#add").attr("data-id");
		$("#ueId").attr("value",ueId);
		$('#myModal').modal("hide");
		$.post("FieldsServlet?method=getFieldListByFieldId", {ueId: ueId},
				function(result){
			
					var result = eval('('+result+')');
					if(result != null){
						$("#fields").empty();
						$("#fields").append(" <option value='0'>请选择...</option>"); 
						for(var i = 0; i < result.length; i++){
							$("#fields").append("<option value='" + result[i].id + "'>" + result[i].fieldName + "</option>"); 
						}
					}
				}
			);
		
		
	})
	
		$("#del").click(function(event){
			var ueId = id;
			$.post("AdminServlet?method=delefc",{ueId: id},
			function(result){
				if(result >= 1){
					alert("删除条件信息成功");
				}
				else
					alert("删除条件信息成功");
			$("#efcListBody").load("EventFieldsConditionServlet?method=getFieldListByUeid&ueId="+ueId);
			}		
			);
		});
	
	
	$("#submit").click(function(){
			if(checkForm()==false){
				return false;
			}
			$.post("EventFieldsConditionServlet?method=addEventFilesCondition",$('#addEventFieldsCondition').serialize(),
			function(result){
				alert("添加成功");
			}		
			);
		});
		var checkForm =function(){
			var fields = document.getElementById("fields").value;
			var condition = document.getElementById("condition").value;
			var value = document.getElementById("value").value;
			if(fields==0){
				return false;
			}else if(condition==0){
				return false;
			}else if(isNaN(value)){
				return false;
			}
			return true;
		
		};
	
</script>
	